package com.fxz.rabbitmq.producer.broker;

import com.fxz.rabbitmq.api.MessageProducer;
import com.fxz.rabbitmq.api.SendCallback;
import com.fxz.rabbitmq.api.enums.MessageTypeEnum;
import com.fxz.rabbitmq.api.exception.MessageException;
import com.fxz.rabbitmq.api.pojo.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 发送消息的实际实现类
 *
 * @author Fxz
 * @version 1.0
 * @date 2021-08-17 13:37
 */
@Component
public class ProducerClient implements MessageProducer {

    @Autowired
    private RabbitBroker rabbitBroker;

    @Override
    public void send(Message message) throws MessageException {
        if (StringUtils.isEmpty(message.getTopic())) {
            throw new MessageException("topic为空!");
        }
        String messageType = message.getMessageType();
        String enumCodeByType = MessageTypeEnum.getStringByCode(messageType);
        switch (enumCodeByType) {
            case "RAPID":
                rabbitBroker.rapidSend(message);
                break;
            case "CONFIRM":
                rabbitBroker.confirmSend(message);
                break;
            case "RELIANT":
                rabbitBroker.reliantSend(message);
                break;
            default:
                break;
        }
    }

    @Override
    public void send(List<Message> messages) {

    }

    @Override
    public void send(Message message, SendCallback sendCallback) {

    }
}
